import markdown

class MarkdownViewMixin:
    ext_name = ".md"
    extensions = ['codehilite', 'extra', 'meta']
    root = None
    base_template = '/base'
    safe_mode = True
    output_format = 'xhtml1'

    #_filters_ = [cache]
    
    def GET(self, filename):
        path = safejoin(self.root, filename + ext_name)
        md = markdown.Markdown(
                extensions=self.extensions,
                safe_mode=self.safe_mode, 
                output_format=self.output_format)

        with open(filename) as f:
            content = md.convert(f.read())
        metadata = md.Meta
        metadata['content'] = content
        return self.render(template_name=base_template, **metadata)

